package com.lw.mall.service2.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lw.mall.entity.Evaluation;
import com.lw.mall.entity.User;
import com.lw.mall.mapper.EvaluationMapper;
import com.lw.mall.service2.EvaluationService2;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lw
 * @since 2022-09-25
 */
@Service
public class EvaluationServiceImpl extends ServiceImpl<EvaluationMapper, Evaluation> implements EvaluationService2 {

    //保存
    @Override
    public void saveContext(String context, User user, Integer productId) {
        final Evaluation evaluation = new Evaluation();
        evaluation.setContent(context);
        evaluation.setCommentTime(new Date());
        evaluation.setProductId(productId);
        evaluation.setUserId(user.getId());
        evaluation.setUserName(user.getUsername());
        baseMapper.insert(evaluation);
    }

    @Override
    public List<Evaluation> getContext(Integer productId) {

        final List<Evaluation> evaluations = baseMapper.selectList(new LambdaQueryWrapper<Evaluation>().eq(Evaluation::getProductId, productId));

        return evaluations;

    }
}
